home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 22 / macformat_22.iso / Shareware / Programación / The Gray Council 1.1 / projects / MacApp / UMyApplication.cp < prev    next >
Encoding:
Text File  |  1996-08-08  |  24.8 KB  |  797 lines  |  [TEXT/CWIE]

  1. //
  2. // GrayCouncil
  3. // Copyright ©1996 by Trygve Isaacson. All Rights Reserved.
  4. //
  5. // This file contains the GrayCouncil MacApp test program's
  6. // application class implementation.
  7. //
  8.  
  9. #include "UMyApplication.h"
  10.  
  11. #include "MyConstants.h"
  12.  
  13. //
  14. // TMyApplication -------------------------------------------------------------------------
  15. //
  16.  
  17. #undef Inherited
  18. #define Inherited TApplication
  19.  
  20. #pragma segment AMyApplication
  21. MA_DEFINE_CLASS_M1(TMyApplication, Inherited);
  22.  
  23. TMyApplication::TMyApplication()
  24.     {
  25.     // Init the pointers & stuff used during idling.
  26.     mProgressIndicator1 = NULL;
  27.     mProgressIndicator2 = NULL;
  28.     mMovingProgressOrigin = FALSE;
  29.     mSkipNext = FALSE;
  30.     }
  31.  
  32. TMyApplication::~TMyApplication()
  33.     {
  34.     }
  35.  
  36. void TMyApplication::IMyApplication()
  37.     {
  38.     FailOSErr(InitGrayCouncilMA());
  39.  
  40.     this->IApplication('????', '????');
  41.     
  42.     // Tell MacApp we don't want an Untitled document created at launch.
  43.     fLaunchWithNewDocument = FALSE;
  44.     
  45.     this->SetIdleFreq(2);
  46.     
  47.     // Create our main window.
  48.  
  49.     TWindow* aWindow;
  50.     FailNIL(aWindow = gViewServer->NewTemplateWindow(kMainWindowViewID, NULL));
  51.     aWindow->Open();
  52.     
  53.     // Allow the window to be resized, but no smaller than
  54.     // its initial size.
  55.     
  56.     CRect    windowFrame;    
  57.     CPoint    minWindowSize;
  58.     CPoint    maxWindowSize(kMaxCoord, kMaxCoord);
  59.     
  60.     aWindow->GetQDExtent(windowFrame);
  61.     minWindowSize = windowFrame[botRight] - windowFrame[topLeft];
  62.  
  63.     aWindow->SetResizeLimits(minWindowSize, maxWindowSize);
  64.     }
  65.  
  66. void TMyApplication::DoSetupMenus()
  67.     {
  68.     Inherited::DoSetupMenus();
  69.     
  70.     // Enable all of the Test menu commands.
  71.     for (UInt32 i = 0; i < kNumDialogs; i++)
  72.         Enable(kMyCommandBase + i, TRUE);
  73.     }
  74.  
  75. void TMyApplication::DoMenuCommand(CommandNumber aCommand)
  76.     {
  77.     // Handle the Test menu commands.
  78.  
  79.     if ((aCommand - kMyCommandBase >= 0) &&
  80.         (aCommand - kMyCommandBase < kNumDialogs))
  81.         this->PoseExampleDialog(aCommand - kMyCommandBase);
  82.     else
  83.         Inherited::DoMenuCommand(aCommand);
  84.     }
  85.  
  86. void TMyApplication::DoEvent(EventNumber eventNumber, TEventHandler* source, TEvent* event)
  87.     {
  88.     IDType        sourceID = source->GetIdentifier();
  89.     UInt32        buttonDialogIndex = sourceID;    // main window buttons are ID'd as kMyViewBase + dialogIndex
  90.  
  91.     if ((buttonDialogIndex >= kMyViewBase) && (buttonDialogIndex < (kMyViewBase + kNumDialogs)))
  92.         this->PoseExampleDialog(buttonDialogIndex - kMyViewBase);
  93.     else
  94.         {
  95.         switch (sourceID)
  96.             {
  97.             case 'ENAB':
  98.                 {
  99.                 // Enable or disable everything in the button's dialog.
  100.  
  101.                 TCheckBox*    aCheckBox = (TCheckBox*) source;
  102.                 TWindow*    aWindow = aCheckBox->GetWindow();
  103.                 
  104.                 this->EnableDisableDialog(mCurrentDialogIndex, aWindow, aCheckBox->IsOn());
  105.                 }
  106.                 break;
  107.             case 'SBAR':
  108.                 {
  109.                 // The scroll bar dialog's TScrollBar was hit.
  110.                 // Update the text that displays the TScrollBar value.
  111.  
  112.                 TScrollBar*        aScrollBar = (TScrollBar*) source;
  113.                 TWindow*        aWindow = aScrollBar->GetWindow();
  114.                 TStaticText*    valueText = (TStaticText*) aWindow->FindSubView('SBTX');
  115.                 SInt32            scrollBarValue = aScrollBar->GetLongVal();
  116.                 CStr255            valueString;
  117.                 
  118.                 ::NumToString(scrollBarValue, valueString);
  119.                 
  120.                 valueText->SetText(valueString, kRedraw);
  121.                 }
  122.                 break;
  123.             case 'LIVE':
  124.             case 'PROP':
  125.                 {
  126.                 // The scroll bar dialog had one of its checkboxes hit.
  127.                 // Toggle the appropriate attribute of the 3 scroll bars
  128.                 // in the dialog.
  129.  
  130.                 AGAScrollerScrollBarMA*    aScrollerScrollBar;
  131.                 TWindow*    aWindow = ((TCheckBox*) source)->GetWindow();
  132.                 TCheckBox*    liveCheckBox = (TCheckBox*) aWindow->FindSubView('LIVE');
  133.                 TCheckBox*    propCheckBox = (TCheckBox*) aWindow->FindSubView('PROP');
  134.  
  135.                 aScrollerScrollBar = (AGAScrollerScrollBarMA*) aWindow->FindSubView('HSBR');
  136.                 aScrollerScrollBar->mAGAObject->SetAttributes(AGAObject::kHorizontal, liveCheckBox->IsOn(), propCheckBox->IsOn());
  137.                 aScrollerScrollBar->UpdateScrollAmounts();
  138.                 
  139.                 if (sourceID == 'PROP')
  140.                     aScrollerScrollBar->ForceRedraw();
  141.  
  142.                 aScrollerScrollBar = (AGAScrollerScrollBarMA*) aWindow->FindSubView('VSBR');
  143.                 aScrollerScrollBar->mAGAObject->SetAttributes(AGAObject::kVertical, liveCheckBox->IsOn(), propCheckBox->IsOn());
  144.                 aScrollerScrollBar->UpdateScrollAmounts();
  145.                 
  146.                 if (sourceID == 'PROP')
  147.                     aScrollerScrollBar->ForceRedraw();
  148.  
  149.                 AGAScrollBarMA*    aScrollBar = (AGAScrollBarMA*) aWindow->FindSubView('SBAR');
  150.                 aScrollBar->mAGAObject->SetAttributes(AGAObject::kHorizontal, liveCheckBox->IsOn(), propCheckBox->IsOn());
  151.                 
  152.                 if (sourceID == 'PROP')
  153.                     aScrollBar->ForceRedraw();
  154.                 }
  155.                 break;
  156.  
  157.             case 'LVSL':
  158.             case 'PRSL':
  159.                 {
  160.                 // The slider dialog had one of its checkboxes hit.
  161.                 // Toggle the appropriate attribute of all sliders
  162.                 // in the dialog.
  163.  
  164.                 AGASliderMA*    aSlider;
  165.                 TWindow*        aWindow = ((TCheckBox*) source)->GetWindow();
  166.                 TCheckBox*        liveCheckBox = (TCheckBox*) aWindow->FindSubView('LVSL');
  167.                 TCheckBox*        propCheckBox = (TCheckBox*) aWindow->FindSubView('PRSL');
  168.  
  169.                 aSlider = (AGASliderMA*) aWindow->FindSubView('VSPL');
  170.                 aSlider->mAGAObject->SetAttributes(AGAObject::kVertical, liveCheckBox->IsOn(), propCheckBox->IsOn());
  171.                 if (sourceID == 'PRSL') aSlider->ForceRedraw();
  172.  
  173.                 aSlider = (AGASliderMA*) aWindow->FindSubView('VSPR');
  174.                 aSlider->mAGAObject->SetAttributes(AGAObject::kVertical, liveCheckBox->IsOn(), propCheckBox->IsOn());
  175.                 if (sourceID == 'PRSL') aSlider->ForceRedraw();
  176.  
  177.                 aSlider = (AGASliderMA*) aWindow->FindSubView('VSRC');
  178.                 aSlider->mAGAObject->SetAttributes(AGAObject::kVertical, liveCheckBox->IsOn(), propCheckBox->IsOn());
  179.                 if (sourceID == 'PRSL') aSlider->ForceRedraw();
  180.  
  181.                 aSlider = (AGASliderMA*) aWindow->FindSubView('HSPL');
  182.                 aSlider->mAGAObject->SetAttributes(AGAObject::kHorizontal, liveCheckBox->IsOn(), propCheckBox->IsOn());
  183.                 if (sourceID == 'PRSL') aSlider->ForceRedraw();
  184.  
  185.                 aSlider = (AGASliderMA*) aWindow->FindSubView('HSPR');
  186.                 aSlider->mAGAObject->SetAttributes(AGAObject::kHorizontal, liveCheckBox->IsOn(), propCheckBox->IsOn());
  187.                 if (sourceID == 'PRSL') aSlider->ForceRedraw();
  188.  
  189.                 aSlider = (AGASliderMA*) aWindow->FindSubView('HSRC');
  190.                 aSlider->mAGAObject->SetAttributes(AGAObject::kHorizontal, liveCheckBox->IsOn(), propCheckBox->IsOn());
  191.                 if (sourceID == 'PRSL') aSlider->ForceRedraw();
  192.                 }
  193.                 break;
  194.  
  195.             case 'GO_1':
  196.                 {
  197.                 // Save the pointer to the determinate progress indicator,
  198.                 // so we'll increment it at idle. Swap the enable states
  199.                 // of its Go and Stop buttons.
  200.  
  201.                 TButton*    buttonToDisable = (TButton*) source;
  202.                 TWindow*    aWindow = buttonToDisable->GetWindow();
  203.                 TButton*    buttonToEnable = (TButton*) aWindow->FindSubView('STP1');
  204.                 
  205.                 this->ToggleButtons(buttonToDisable, buttonToEnable);
  206.                 
  207.                 mProgressIndicator1 = (AGAProgressIndicatorMA*) aWindow->FindSubView('PRG1');
  208.                 }
  209.                 break;
  210.             
  211.             case 'GO_2':
  212.                 {
  213.                 // Null the pointer to the determinate progress indicator,
  214.                 // so we'll ignore it at idle. Swap the enable states
  215.                 // of its Go and Stop buttons.
  216.  
  217.                 TButton*    buttonToDisable = (TButton*) source;
  218.                 TWindow*    aWindow = buttonToDisable->GetWindow();
  219.                 TButton*    buttonToEnable = (TButton*) aWindow->FindSubView('STP2');
  220.                 
  221.                 this->ToggleButtons(buttonToDisable, buttonToEnable);
  222.                 
  223.                 mProgressIndicator2 = (AGAProgressIndicatorMA*) aWindow->FindSubView('PRG2');
  224.                 }
  225.                 break;
  226.             
  227.             case 'STP1':
  228.                 {
  229.                 // Save the pointer to the indeterminate progress indicator,
  230.                 // so we'll increment it at idle. Swap the enable states
  231.                 // of its Go and Stop buttons.
  232.  
  233.                 TButton*    buttonToDisable = (TButton*) source;
  234.                 TWindow*    aWindow = buttonToDisable->GetWindow();
  235.                 TButton*    buttonToEnable = (TButton*) aWindow->FindSubView('GO_1');
  236.                 
  237.                 this->ToggleButtons(buttonToDisable, buttonToEnable);
  238.                 
  239.                 mProgressIndicator1 = NULL;
  240.                 }
  241.                 break;
  242.             
  243.             case 'STP2':
  244.                 {
  245.                 // Null the pointer to the indeterminate progress indicator,
  246.                 // so we'll ignore it at idle. Swap the enable states
  247.                 // of its Go and Stop buttons.
  248.  
  249.                 TButton*    buttonToDisable = (TButton*) source;
  250.                 TWindow*    aWindow = buttonToDisable->GetWindow();
  251.                 TButton*    buttonToEnable = (TButton*) aWindow->FindSubView('GO_2');
  252.                 
  253.                 this->ToggleButtons(buttonToDisable, buttonToEnable);
  254.                 
  255.                 mProgressIndicator2 = NULL;
  256.                 }
  257.                 break;
  258.             
  259.             case 'CORG':
  260.                 {
  261.                 // The progress dialog's "Moving Origin" checkbox was hit.
  262.                 // Enable or disable the edit text and little arrows, and
  263.                 // set our flag that we'll check at idle.
  264.  
  265.                 TCheckBox*    aCheckBox = (TCheckBox*) source;
  266.                 TWindow*    aWindow = aCheckBox->GetWindow();
  267.                 Boolean        enabled = aCheckBox->IsOn();
  268.                 TControl*    aControl;
  269.                 
  270.                 aControl = (TControl*) aWindow->FindSubView('NORG');
  271.                 ((TEditText*) aControl)->StopEdit();
  272.                 aControl->SetEnable(enabled);
  273.                 aControl->DimState(! enabled, kRedraw);
  274.                 
  275.                 aControl = (TControl*) aWindow->FindSubView('AORG');
  276.                 aControl->SetEnable(enabled);
  277.                 aControl->DimState(! enabled, kRedraw);
  278.                 
  279.                 aControl = (TControl*) aWindow->FindSubView('TORG');
  280.                 aControl->SetEnable(enabled);
  281.                 aControl->DimState(! enabled, kRedraw);
  282.                 
  283.                 mMovingProgressOrigin = enabled;
  284.                 }
  285.                 break;
  286.             
  287.             case 'SETV':
  288.                 {
  289.                 // The "Set Values" button in the progress dialog was hit.
  290.                 // Poke the determinate progress indicator with the current
  291.                 // values that have been entered in the dialog.
  292.  
  293.                 TWindow*        aWindow = ((TButton*) source)->GetWindow();
  294.                 TNumberText*    aNumberText;
  295.                 TCheckBox*        originCheckBox = (TCheckBox*) aWindow->FindSubView('CORG');
  296.                 SInt32            newMin;
  297.                 SInt32            newMax;
  298.                 SInt32            newValue;
  299.                 SInt32            newOrigin;
  300.  
  301.                 AGAProgressIndicatorMA*    indicator = (AGAProgressIndicatorMA*) aWindow->FindSubView('PRG2');
  302.                 
  303.                 aNumberText = (TNumberText*) aWindow->FindSubView('NMIN');
  304.                 newMin = aNumberText->GetValue();
  305.                 
  306.                 aNumberText = (TNumberText*) aWindow->FindSubView('NMAX');
  307.                 newMax = aNumberText->GetValue();
  308.                 
  309.                 indicator->mAGAObject->SetRange(newMin, newMax, kDontRedraw);
  310.                 
  311.                 aNumberText = (TNumberText*) aWindow->FindSubView('NVAL');
  312.                 newValue = aNumberText->GetValue();
  313.                 indicator->mAGAObject->SetValue(newValue, kDontRedraw);
  314.                 
  315.                 if (! originCheckBox->IsOn())
  316.                     newOrigin = newMin;
  317.                 else
  318.                     {
  319.                     aNumberText = (TNumberText*) aWindow->FindSubView('NORG');
  320.                     newOrigin = Max(newMin, aNumberText->GetValue());
  321.                     }
  322.                 
  323.                 indicator->mAGAObject->SetOriginValue(newOrigin, kDontRedraw);
  324.                 
  325.                 indicator->ForceRedraw();
  326.                 }
  327.                 break;
  328.  
  329.             case 'EDCB':
  330.                 {
  331.                 // Enable or disable the first field of the edit text dialog.
  332.  
  333.                 TCheckBox*    aCheckBox = (TCheckBox*) source;
  334.                 TWindow*    aWindow = aCheckBox->GetWindow();
  335.                 Boolean        enabled = aCheckBox->IsOn();
  336.                 TEditText*    anEditText = (TEditText*) aWindow->FindSubView('EDT1');
  337.  
  338.                 anEditText->StopEdit();
  339.                 anEditText->SetEnable(enabled);
  340.                 anEditText->DimState(! enabled, kRedraw);
  341.                 }
  342.                 break;
  343.  
  344.             case 'ENL1':
  345.                 {
  346.                 // Enable or disable the first box of the focus border dialog.
  347.  
  348.                 TCheckBox*    aCheckBox = (TCheckBox*) source;
  349.                 TWindow*    aWindow = aCheckBox->GetWindow();
  350.                 Boolean        enabled = aCheckBox->IsOn();
  351.  
  352.                 TTargetBorderView*    border = (TTargetBorderView*) aWindow->FindSubView('BRD1');
  353.                 TView*                targetableView = border->FindSubView('TVW1');
  354.  
  355.                 if ((! enabled) && border->ContainsTarget(gApplication->GetTarget()))
  356.                     targetableView->ResignTarget();
  357.  
  358.                 border->SetEnable(enabled);
  359.                 targetableView->SetEnable(enabled);
  360.                 }
  361.                 break;
  362.  
  363.             }
  364.         }
  365.     
  366.     Inherited::DoEvent(eventNumber, source, event);
  367.     }
  368.  
  369. void TMyApplication::ToggleButtons(TButton* buttonToDisable, TButton* buttonToEnable)
  370.     {
  371.     buttonToDisable->SetEnable(FALSE);
  372.     buttonToDisable->DimState(TRUE, kRedraw);
  373.  
  374.     buttonToEnable->SetEnable(TRUE);
  375.     buttonToEnable->DimState(FALSE, kRedraw);
  376.     }
  377.  
  378. Boolean TMyApplication::DoIdle(IdlePhase phase)
  379.     {
  380.     // If we have a pointer to the indeterminate progress indicator,
  381.     // crank it once.
  382.     if (mProgressIndicator1 != NULL)
  383.         if (mProgressIndicator1->Focus())
  384.             mProgressIndicator1->mAGAObject->Animate();
  385.  
  386.     // If we have a pointer to the determinate progress indicator,
  387.     // increment its value.
  388.     if (mProgressIndicator2 != NULL)
  389.         if (mProgressIndicator2->Focus())
  390.             {
  391.             mProgressIndicator2->mAGAObject->Increment(1, kRedraw);
  392.             
  393.             // Increment the origin every other time, if it's moving.
  394.             if (mMovingProgressOrigin && ! mSkipNext)
  395.                 mProgressIndicator2->mAGAObject->SetOriginValue(1 + mProgressIndicator2->mAGAObject->GetOriginValue(), kRedraw);
  396.             
  397.             mSkipNext = ! mSkipNext;    // make moving origin go slower than value
  398.             }
  399.  
  400.     return FALSE;    // did not free self
  401.     }
  402.  
  403. void TMyApplication::PoseExampleDialog(UInt32 dialogIndex)
  404.     {
  405.     // Run the specified dialog.
  406.  
  407.     TWindow    *aWindow;
  408.  
  409.     FailNIL(aWindow = gViewServer->NewTemplateWindow(kMyViewBase + dialogIndex, NULL));
  410.     
  411.     mCurrentDialogIndex = dialogIndex;
  412.     
  413.     this->SetupExampleDialog(dialogIndex, aWindow);
  414.     
  415.     (void) aWindow->PoseModally();
  416.     
  417.     this->CleanupExampleDialog(dialogIndex, aWindow);
  418.     
  419.     aWindow->CloseAndFree();
  420.     }
  421.  
  422. void TMyApplication::SetupExampleDialog(UInt32 dialogIndex, TWindow* itsWindow)
  423.     {
  424.     // Note that when we set AGAObject states & values here, we tell it
  425.     // not to redraw right now, because the dialog isn't visible yet.
  426.     // If we *did* tell it to redraw, we would have to Focus() it first
  427.     // so that the AGAObject would be drawing into the correct GrafPort.
  428.  
  429.     switch (dialogIndex)
  430.         {
  431.         case kCheckBoxDlgIndex:
  432.             {
  433.             AGACheckBoxMA*    mixedCheckBox;
  434.             FailNIL(mixedCheckBox = (AGACheckBoxMA*) itsWindow->FindSubView('BTN3'));
  435.             mixedCheckBox->mAGAObject->SetValue(AGACheckBox::kCheckBoxMixed, AGAObject::kDontRedraw);
  436.             }
  437.             break;
  438.         case kRadioButtonDlgIndex:
  439.             {
  440.             AGARadioButtonMA*    mixedRadioButton;
  441.             FailNIL(mixedRadioButton = (AGARadioButtonMA*) itsWindow->FindSubView('BTN3'));
  442.             mixedRadioButton->mAGAObject->SetValue(AGARadioButton::kRadioButtonMixed, AGAObject::kDontRedraw);
  443.             }
  444.             break;
  445.         case kScrollBarDlgIndex:
  446.             {
  447.             AGAScrollBarMA    *aScrollBar = (AGAScrollBarMA*) itsWindow->FindSubView('SBAR');
  448.             aScrollBar->mAGAObject->SetPageSize(25, AGAObject::kDontRedraw);
  449.             aScrollBar->mAGAObject->SetStepSizes(1, 25);
  450.             }
  451.             break;
  452.         case kSliderDlgIndex:
  453.             {
  454.             AGASliderMA*    aSlider;
  455.  
  456.             FailNIL(aSlider = (AGASliderMA*) itsWindow->FindSubView('HSPL'));
  457.             aSlider->mAGAObject->SetRange(0, 100, AGAObject::kDontRedraw);
  458.             aSlider->mAGAObject->SetPageSize(1, AGAObject::kDontRedraw);
  459.  
  460.             FailNIL(aSlider = (AGASliderMA*) itsWindow->FindSubView('VSPR'));
  461.             aSlider->mAGAObject->SetJustification(teFlushRight);
  462.             aSlider->mAGAObject->SetPageSize(1, AGAObject::kDontRedraw);
  463.  
  464.             FailNIL(aSlider = (AGASliderMA*) itsWindow->FindSubView('HSPR'));
  465.             aSlider->mAGAObject->SetJustification(teFlushRight);
  466.             aSlider->mAGAObject->SetRange(0, 32, AGAObject::kDontRedraw);
  467.             aSlider->mAGAObject->SetPageSize(1, AGAObject::kDontRedraw);
  468.  
  469.             FailNIL(aSlider = (AGASliderMA*) itsWindow->FindSubView('VSPL'));
  470.             aSlider->mAGAObject->SetPageSize(1, AGAObject::kDontRedraw);
  471.  
  472.             FailNIL(aSlider = (AGASliderMA*) itsWindow->FindSubView('VSRC'));
  473.             aSlider->mAGAObject->SetRange(0, 100, AGAObject::kDontRedraw);
  474.             aSlider->mAGAObject->SetPageSize(20, AGAObject::kDontRedraw);
  475.  
  476.             FailNIL(aSlider = (AGASliderMA*) itsWindow->FindSubView('HSRC'));
  477.             aSlider->mAGAObject->SetRange(0, 100, AGAObject::kDontRedraw);
  478.             aSlider->mAGAObject->SetPageSize(20, AGAObject::kDontRedraw);
  479.             }
  480.             break;
  481.         case kDisclosureDlgIndex:
  482.             {
  483.             AGADisclosureTriangleMA*    aTriangle;
  484.             FailNIL(aTriangle = (AGADisclosureTriangleMA*) itsWindow->FindSubView('DIS3'));
  485.             aTriangle->mAGAObject->SetState(AGADisclosureTriangle::kDisclosedState, AGAObject::kDontRedraw);
  486.             }
  487.             break;
  488.         case kProgressDlgIndex:
  489.             {
  490.             AGAProgressIndicatorMA*    aProgressIndicator;
  491.             FailNIL(aProgressIndicator = (AGAProgressIndicatorMA*) itsWindow->FindSubView('PRG1'));
  492.             aProgressIndicator->mAGAObject->SetRange(0, 0, AGAObject::kDontRedraw);
  493.             }
  494.             break;
  495.         }
  496.     }
  497.  
  498. void TMyApplication::CleanupExampleDialog(UInt32 dialogIndex, TWindow* itsWindow)
  499.     {
  500.     switch (dialogIndex)
  501.         {
  502.         case kProgressDlgIndex:
  503.             {
  504.             // Null the pointers so we don't go haywire at next DoIdle !
  505.  
  506.             mProgressIndicator1 = NULL;
  507.             mProgressIndicator2 = NULL;
  508.             mMovingProgressOrigin = FALSE;
  509.             mSkipNext = FALSE;
  510.             }
  511.             break;
  512.         }
  513.     }
  514.  
  515. void TMyApplication::EnableDisableDialog(UInt32 dialogIndex, TWindow* itsWindow, Boolean enable)
  516.     {
  517.     // Find all of the appropriate items of the specified dialog,
  518.     // and set their enable/disable/dim state as requested.
  519.  
  520.     TControl*    aControl;
  521.     
  522.     switch (dialogIndex)
  523.         {
  524.         case kPushButtonDlgIndex:
  525.  
  526.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('BTN1'));
  527.             aControl->SetEnable(enable);
  528.             aControl->DimState(! enable, kRedraw);
  529.             
  530.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('BTN2'));
  531.             aControl->SetEnable(enable);
  532.             aControl->DimState(! enable, kRedraw);
  533.             
  534.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN1'));
  535.             aControl->SetEnable(enable);
  536.             aControl->DimState(! enable, kRedraw);
  537.             
  538.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN2'));
  539.             aControl->SetEnable(enable);
  540.             aControl->DimState(! enable, kRedraw);
  541.             
  542.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN3'));
  543.             aControl->SetEnable(enable);
  544.             aControl->DimState(! enable, kRedraw);
  545.             
  546.             break;
  547.  
  548.         case kCheckBoxDlgIndex:
  549.  
  550.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('BTN1'));
  551.             aControl->SetEnable(enable);
  552.             aControl->DimState(! enable, kRedraw);
  553.             
  554.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('BTN2'));
  555.             aControl->SetEnable(enable);
  556.             aControl->DimState(! enable, kRedraw);
  557.             
  558.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('BTN3'));
  559.             aControl->SetEnable(enable);
  560.             aControl->DimState(! enable, kRedraw);
  561.             
  562.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN1'));
  563.             aControl->SetEnable(enable);
  564.             aControl->DimState(! enable, kRedraw);
  565.             
  566.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN2'));
  567.             aControl->SetEnable(enable);
  568.             aControl->DimState(! enable, kRedraw);
  569.             
  570.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN3'));
  571.             aControl->SetEnable(enable);
  572.             aControl->DimState(! enable, kRedraw);
  573.  
  574.             break;
  575.  
  576.         case kRadioButtonDlgIndex:
  577.  
  578.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('BTN1'));
  579.             aControl->SetEnable(enable);
  580.             aControl->DimState(! enable, kRedraw);
  581.             
  582.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('BTN2'));
  583.             aControl->SetEnable(enable);
  584.             aControl->DimState(! enable, kRedraw);
  585.             
  586.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('BTN3'));
  587.             aControl->SetEnable(enable);
  588.             aControl->DimState(! enable, kRedraw);
  589.             
  590.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN1'));
  591.             aControl->SetEnable(enable);
  592.             aControl->DimState(! enable, kRedraw);
  593.             
  594.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN2'));
  595.             aControl->SetEnable(enable);
  596.             aControl->DimState(! enable, kRedraw);
  597.             
  598.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN3'));
  599.             aControl->SetEnable(enable);
  600.             aControl->DimState(! enable, kRedraw);
  601.  
  602.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN4'));
  603.             aControl->SetEnable(enable);
  604.             aControl->DimState(! enable, kRedraw);
  605.  
  606.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN5'));
  607.             aControl->SetEnable(enable);
  608.             aControl->DimState(! enable, kRedraw);
  609.  
  610.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN6'));
  611.             aControl->SetEnable(enable);
  612.             aControl->DimState(! enable, kRedraw);
  613.  
  614.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('ICN7'));
  615.             aControl->SetEnable(enable);
  616.             aControl->DimState(! enable, kRedraw);
  617.  
  618.             break;
  619.  
  620.         case kScrollBarDlgIndex:
  621.  
  622.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('SBAR'));
  623.             aControl->SetEnable(enable);
  624.             aControl->DimState(! enable, kRedraw);
  625.  
  626.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('HSBR'));
  627.             aControl->SetEnable(enable);
  628.             aControl->DimState(! enable, kRedraw);
  629.  
  630.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('VSBR'));
  631.             aControl->SetEnable(enable);
  632.             aControl->DimState(! enable, kRedraw);
  633.  
  634.             break;
  635.  
  636.         case kSliderDlgIndex:
  637.  
  638.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('VSPL'));
  639.             aControl->SetEnable(enable);
  640.             aControl->DimState(! enable, kRedraw);
  641.             
  642.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('VSPR'));
  643.             aControl->SetEnable(enable);
  644.             aControl->DimState(! enable, kRedraw);
  645.             
  646.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('VSRC'));
  647.             aControl->SetEnable(enable);
  648.             aControl->DimState(! enable, kRedraw);
  649.             
  650.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('HSPL'));
  651.             aControl->SetEnable(enable);
  652.             aControl->DimState(! enable, kRedraw);
  653.             
  654.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('HSPR'));
  655.             aControl->SetEnable(enable);
  656.             aControl->DimState(! enable, kRedraw);
  657.             
  658.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('HSRC'));
  659.             aControl->SetEnable(enable);
  660.             aControl->DimState(! enable, kRedraw);
  661.  
  662.             break;
  663.  
  664.         case kPopupMenuDlgIndex:
  665.  
  666.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('POP1'));
  667.             aControl->SetEnable(enable);
  668.             aControl->DimState(! enable, kRedraw);
  669.  
  670.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('POP2'));
  671.             aControl->SetEnable(enable);
  672.             aControl->DimState(! enable, kRedraw);
  673.  
  674.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('POP3'));
  675.             aControl->SetEnable(enable);
  676.             aControl->DimState(! enable, kRedraw);
  677.  
  678.             break;
  679.  
  680.         case kGroupBoxDlgIndex:
  681.  
  682.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('GRP1'));
  683.             aControl->SetEnable(enable);
  684.             aControl->DimState(! enable, kRedraw);
  685.  
  686.                 FailNIL(aControl = (TControl*) itsWindow->FindSubView('GR1A'));
  687.                 aControl->SetEnable(enable);
  688.                 aControl->DimState(! enable, kRedraw);
  689.  
  690.                     FailNIL(aControl = (TControl*) itsWindow->FindSubView('R1A1'));
  691.                     aControl->SetEnable(enable);
  692.                     aControl->DimState(! enable, kRedraw);
  693.  
  694.                     FailNIL(aControl = (TControl*) itsWindow->FindSubView('R1A2'));
  695.                     aControl->SetEnable(enable);
  696.                     aControl->DimState(! enable, kRedraw);
  697.  
  698.                 FailNIL(aControl = (TControl*) itsWindow->FindSubView('GR1B'));
  699.                 aControl->SetEnable(enable);
  700.                 aControl->DimState(! enable, kRedraw);
  701.  
  702.                     FailNIL(aControl = (TControl*) itsWindow->FindSubView('R1B1'));
  703.                     aControl->SetEnable(enable);
  704.                     aControl->DimState(! enable, kRedraw);
  705.  
  706.                     FailNIL(aControl = (TControl*) itsWindow->FindSubView('R1B2'));
  707.                     aControl->SetEnable(enable);
  708.                     aControl->DimState(! enable, kRedraw);
  709.  
  710.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('GRP2'));
  711.             aControl->SetEnable(enable);
  712.             aControl->DimState(! enable, kRedraw);
  713.  
  714.                 FailNIL(aControl = (TControl*) itsWindow->FindSubView('GR2A'));
  715.                 aControl->SetEnable(enable);
  716.                 aControl->DimState(! enable, kRedraw);
  717.  
  718.                     FailNIL(aControl = (TControl*) itsWindow->FindSubView('R2A1'));
  719.                     aControl->SetEnable(enable);
  720.                     aControl->DimState(! enable, kRedraw);
  721.  
  722.                     FailNIL(aControl = (TControl*) itsWindow->FindSubView('R2A2'));
  723.                     aControl->SetEnable(enable);
  724.                     aControl->DimState(! enable, kRedraw);
  725.  
  726.                 FailNIL(aControl = (TControl*) itsWindow->FindSubView('GR2B'));
  727.                 aControl->SetEnable(enable);
  728.                 aControl->DimState(! enable, kRedraw);
  729.  
  730.                     FailNIL(aControl = (TControl*) itsWindow->FindSubView('R2B1'));
  731.                     aControl->SetEnable(enable);
  732.                     aControl->DimState(! enable, kRedraw);
  733.  
  734.                     FailNIL(aControl = (TControl*) itsWindow->FindSubView('R2B2'));
  735.                     aControl->SetEnable(enable);
  736.                     aControl->DimState(! enable, kRedraw);
  737.  
  738.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('CBX1'));
  739.             aControl->SetEnable(enable);
  740.             aControl->DimState(! enable, kRedraw);
  741.  
  742.             FailNIL(aControl = (TControl*) itsWindow->FindSubView('GRP3'));
  743.             aControl->SetEnable(enable);
  744.             aControl->DimState(! enable, kRedraw);
  745.  
  746.                 FailNIL(aControl = (TControl*) itsWindow->FindSubView('CBX2'));
  747.                 aControl->SetEnable(enable);
  748.                 aControl->DimState(! enable, kRedraw);
  749.  
  750.                 FailNIL(aControl = (TControl*) itsWindow->FindSubView('GR3A'));
  751.                 aControl->SetEnable(enable);
  752.                 aControl->DimState(! enable, kRedraw);
  753.  
  754.                     FailNIL(aControl = (TControl*) itsWindow->FindSubView('R3A1'));
  755.                     aControl->SetEnable(enable);
  756.                     aControl->DimState(! enable, kRedraw);
  757.  
  758.                     FailNIL(aControl = (TControl*) itsWindow->FindSubView('R3A2'));
  759.                     aControl->SetEnable(enable);
  760.                     aControl->DimState(! enable, kRedraw);
  761.  
  762.                 FailNIL(aControl = (TControl*) itsWindow->FindSubView('CBX3'));
  763.                 aControl->SetEnable(enable);
  764.                 aControl->DimState(! enable, kRedraw);
  765.  
  766.                 FailNIL(aControl = (TControl*) itsWindow->FindSubView('GR3B'));
  767.                 aControl->SetEnable(enable);
  768.                 aControl->DimState(! enable, kRedraw);
  769.  
  770.                     FailNIL(aControl = (TControl*) itsWindow->FindSubView('R3B1'));
  771.                     aControl->SetEnable(enable);
  772.                     aControl->DimState(! enable, kRedraw);
  773.  
  774.                     FailNIL(aControl = (TControl*) itsWindow->FindSubView('R3B2'));
  775.                     aControl->SetEnable(enable);
  776.                     aControl->DimState(! enable, kRedraw);
  777.  
  778.             break;
  779.  
  780.         }
  781.     }
  782.  
  783. void TMyApplication::DoAboutBox()
  784.     {
  785.     TWindow*        aWindow;
  786.     TStaticText*    copyrightString;
  787.  
  788.     FailNIL(aWindow = gViewServer->NewTemplateWindow(kAboutBoxViewID, NULL));
  789.     
  790.     FailNIL(copyrightString = (TStaticText*) aWindow->FindSubView('COPY'));
  791.     copyrightString->SetText(gGrayCouncilCopyright, kDontRedraw);
  792.     
  793.     (void) aWindow->PoseModally();
  794.     
  795.     aWindow->CloseAndFree();
  796.     }
  797.